package com.qiaoanju.web.security.handler;

import com.qiaoanju.back.domain.system.UserModel;
import com.qiaoanju.back.service.system.IGroupService;
import com.qiaoanju.back.service.system.IMenuService;
import com.qiaoanju.back.service.system.IRoleService;
import com.qiaoanju.back.service.system.IUserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by eversec
 * on 2017/9/22.
 */
public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {

    private static final Logger logger = LogManager.getLogger();

    @Autowired
    private IUserService userService ;

    @Autowired
    private IMenuService menuService ;

    @Autowired
    private IGroupService groupService ;

    @Autowired
    private IRoleService roleService ;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {


        //
        UserModel user  = (UserModel) authentication.getPrincipal();

        logger.info("用户："+user.getUsername()+" 登录系统成功！");
        super.onAuthenticationSuccess(request, response, authentication);
    }
}
